using GameFrameWork;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/// <summary>
/// 技能效果执行器
/// </summary>
public class SkillExecutor
{
    /// <summary>
    /// 技能效果执行
    /// </summary>
    /// <param name="data"></param>
    /// <param name="caster"></param>
    /// <param name="target"></param>
    public static void Execute(SkillData data, Entity caster, Entity target)
    {
        Execute(data.Effects, caster, target);
    }

    /// <summary>
    /// 技能效果执行
    /// </summary>
    /// <param name="data"></param>
    /// <param name="caster"></param>
    /// <param name="target"></param>
    public static void Execute(List<InstantEffectData> datas, Entity caster, Entity target)
    {
        if (datas.IsNullOrEmpty())
        {
            Logger.Log("SkillExecutor", $"效果列表为空，caster={caster?.name}, target={target?.name}");
            return;
        }

        Logger.Log("SkillExecutor", $"开始执行效果，caster={caster?.name}, target={target?.name}, 效果数量={datas.Count}");

        //Ч
        //TODO

        //Χж
        bool isInRange = true;

        if (!isInRange)
        {
            Logger.LogWarning("SkillExecutor", $"目标不在范围内，caster={caster?.name}, target={target?.name}");
            return;
        }

        //ִЧЧҲᴴЧ
        for (int i = 0; i < datas.Count; i++)
        {
            var fx = datas[i];
            if (fx == null)
            {
                Logger.LogWarning("SkillExecutor", $"效果[{i}]为空，跳过");
                continue;
            }
            
            Logger.Log("SkillExecutor", $"执行效果[{i}]: {fx.GetType().Name}, caster={caster?.name}, target={target?.name}");
            fx.Execute(caster, target, 0);
        }
        
        Logger.Log("SkillExecutor", $"效果执行完成，caster={caster?.name}, target={target?.name}");
    }
}
